package com.heima.service.iml;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.heima.mapper.EmpMapper;
import com.heima.poji.Emp;
import com.heima.poji.pageBean;
import com.heima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;


@Service
public class EmpServiceImp implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public pageBean list(Integer page, Integer pageSize, String name, Short gender, LocalDate begin,
                         LocalDate end) {
//        Long empsum= empMapper.empSum();
//        Integer page1=(page-1)*pageSize;
        PageHelper.startPage(page, pageSize);
        List<Emp> empList = empMapper.list(name, gender, begin, end);
        Page<Emp> p = (Page<Emp>) empList;
        pageBean pagebean = new pageBean(p.getTotal(), p.getResult());
        return pagebean;
    }

    @Override
    public void delectById(List<Integer> ids) {
        empMapper.delectById(ids);
    }

    @Override
    public void insetEmp(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insetEmp(emp);
    }

    @Override
    public Emp SelctById(Integer id) {
        return empMapper.SelctById(id);
    }

    @Override
    public void updateById(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updateById(emp);
    }
}